package com.bw.module_mine.ui.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_mine.R
import com.bw.module_mine.databinding.LayoutToolsItemBinding
import com.bw.module_mine.model.TabItem

/**
 * @author ytx
 * @date 2025-09-20 09:35
 * @description
 */
class ToolAdapter(
    private val mList: List<TabItem>,
    private val mOnItemClickListener: (TabItem) -> Unit
):RecyclerView.Adapter<ToolAdapter.ToolViewHolder>() {


    class ToolViewHolder(val binding:LayoutToolsItemBinding):RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ToolViewHolder {
        val binding =  DataBindingUtil.inflate<LayoutToolsItemBinding>(LayoutInflater.from(p0.context), R.layout.layout_tools_item, p0, false)
        return ToolViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ToolViewHolder, position: Int) {
        //绑定数据
        holder.binding.apply {
            item = mList[position]
//            vRedPoint.visibility = if (mList[position].hasNew) View.VISIBLE else View.GONE
        }
        //点击事件
        holder.binding.lTab.setOnClickListener {
            mOnItemClickListener.invoke(mList[position])
        }

    }


}